package com.xw.controller.example;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.xw.model.sdk.AliSms;
import com.xw.model.sdk.Ucpaas;
import com.xw.service.tool.alisms.AliSmsService;
import com.xw.service.tool.jpush.JPushService;
import com.xw.service.tool.oss.OssService;
import com.xw.service.tool.ucpaas.UcpaasService;
import com.xw.util.zxing.QRCodeUtil;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 12561
 * 测试demo
 */
@Controller
@RequestMapping("/test")
@Scope("prototype")
public class TestController {
    Logger logger  =  Logger.getLogger(TestController.class);
    Map<String,Object> map = null;
    @Resource
    private JPushService jPushService;
    @Resource
    private AliSmsService aliSmsService;
    @Resource
    private UcpaasService ucpaasService;
    @Resource
    private OssService ossService;


    @RequestMapping(value = "/zxing",method = RequestMethod.POST)
    @ResponseBody
    public Object zxing(HttpSession session, String content) throws IOException {
        String zxingqrCode = QRCodeUtil.createZxingqrCode(session, content);
        return zxingqrCode;
    }



    @RequestMapping(value = "/uploadFiles",method = RequestMethod.POST)
    @ResponseBody
    public Object upload(MultipartFile file) throws IOException {
        Map map = ossService.upload(file);
        return map;
    }


    /**
     * 跳转到地图
     * @return
     */
    @RequestMapping(value = "/map",method = RequestMethod.GET)
    public String map(){
        logger.info("跳转到地图");
        return "tools/map";
    }

    /**
     * 跳转到图片视频上传页面（包含上传到七牛云，服务器，本地）
     * @return
     */
    @RequestMapping(value = "/upload",method = RequestMethod.GET)
    public String movieToQiniu(){
        logger.error("跳转到图片视频上传页面（包含上传到七牛云，服务器，本地）");
        return "tools/upload";
    }

    /**
     * 跳转到WangEditor编辑器
     * @return
     */
    @RequestMapping(value = "/toWangEditor",method = RequestMethod.GET)
    public String toWangEditor(){
        logger.error("跳转到WangEditor编辑器");
        return "tools/wangEditor";
    }
    /**
     * 跳转到webuploader
     * @return
     */
    @RequestMapping(value = "/toWebuploader",method = RequestMethod.GET)
    public String toWebuploader(){
        logger.error("跳转到toWebuploader");
        return "tools/webuploader";
    }
    /**
     * 跳转到回显 webuploader 图片
     * @return
     */
    @RequestMapping(value = "/toViewWebuploader",method = RequestMethod.GET)
    public String toViewWebuploader(){
        logger.error("跳转到 toViewWebuploader");
        return "tools/webuploader2";
    }
    /**
     * 跳转到toForm
     * @return
     */
    @RequestMapping(value = "/toForm",method = RequestMethod.GET)
    public String toForm(){
        return "tools/form";
    }

    /**
     * 阿里 短信发送
     * @return
     * @throws ClientException
     */
    @RequestMapping(value = "/sendSms",method = RequestMethod.POST)
    @ResponseBody
    public Object sendSms() throws ClientException {
        map =new HashMap<>();
        Map<String,String> smsMap=new HashMap<>();
        AliSms aliSms = new AliSms();
        aliSms.setPhoneNumber("17512580833");
        aliSms.setSignName("风从Sea面吹过来");
        aliSms.setTemplateCode("SMS_123738115");
        smsMap.put("code","123456");
        aliSms.setMap(smsMap);
        SendSmsResponse sendSms = aliSmsService.sendSms(aliSms);
        if ("ok".equals(sendSms.getCode())){
            map.put("code",200);
            //短信发送返回的一些信息
            map.put("sendSms",sendSms);
        }else{
            map.put("code",101);
            map.put("sendSms",sendSms);
        }
        return map;
    }
    /**
     * 云之讯 发送短信 验证码
     * @return
     * @throws ClientException
     */
    @RequestMapping(value = "/sendUcpaasSms",method = RequestMethod.POST)
    @ResponseBody
    public Object sendUcpaasSms() throws ClientException {
        map =new HashMap<>();
        Ucpaas ucpaas = new Ucpaas();
        ucpaas.setMobile("17512580833");
        ucpaas.setTemplateid("330126");
        ucpaas.setParam("16点,888888");
        ucpaas.setUid("sea");
        Map maps = ucpaasService.sendSms(ucpaas);
        System.out.println("uid >>>>>>>>>>>>>>>>>"+maps.get("uid"));
        if ("000000".equals(maps.get("code"))){
            map.put("code",200);
        }else{
            map.put("code",101);
        }

        return map;
    }

    @RequestMapping(value = "/sendSmsBatch",method = RequestMethod.POST)
    @ResponseBody
    public Object sendSmsBatch() {
        map =new HashMap<>();
        Ucpaas ucpaas = new Ucpaas();
        ucpaas.setMobile("17512580833,17512561162");
        ucpaas.setTemplateid("330126");
        ucpaas.setParam("16点,888888");
        Map maps = ucpaasService.sendSmsBatch(ucpaas);
        if ("000000".equals(maps.get("code"))){
            this.map.put("code",200);
        }else{
            this.map.put("code",101);
        }

        return this.map;
    }

}




